/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spravaSviatkov;

import importExportDat.ImportExportCSV;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.DefaultTableModel;
import strukturaSviatky.Sviatky;
import strukturaSviatky.Sviatok;

/**
 *
 * @author Monika
 */
public class SpravaSviatkov extends javax.swing.JFrame {

    /**
     * Creates new form SpravaSviatkovUI
     */
    private ArrayList<Sviatok> sviatkyZoznam;
    private Sviatky sviatky;
    private ImportExportCSV ie;
    private myDefaultTableModel dtm;

    private class myDefaultTableModel extends DefaultTableModel {

        @Override   //aby v poslednom stlpci boli checkboxy
        public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 2) {
                return Boolean.class;
            } else {
                // returns Object.class  
                return super.getColumnClass(columnIndex);
            }
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return column == 2;
        }
    }

    public SpravaSviatkov() {
        initComponents();

        //centralizovanie okna
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int X = (screen.width / 2) - (this.getWidth() / 2); // Center horizontally.
        int Y = (screen.height / 2) - (this.getHeight() / 2); // Center vertically.
        this.setLocation(X, Y);

        try {
            sviatky = new Sviatky();
        } catch (SQLException | ParseException ex) {
            Logger.getLogger(SpravaSviatkov.class.getName()).log(Level.SEVERE, null, ex);
        }
        ie = new ImportExportCSV(this);

        dtm = new myDefaultTableModel();
        String headers[] = new String[3];
        headers[0] = "Popis sviatku";
        headers[1] = "Dátum";
        headers[2] = "Odstránenie";
        dtm.setColumnIdentifiers(headers);
        dtm.getColumnClass(2);

        ActionListener actionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                refreshTable();
            }
        };
        rokTabulkaCB.addActionListener(actionListener);
        rokTabulkaCB.addItem("všetky");
        for (int i = 2012; i <= Calendar.getInstance().get(Calendar.YEAR) + 1; i++) {
            rokTabulkaCB.addItem(i);
        }
        rokTabulkaCB.setSelectedIndex(0);

        sviatkyTable.setModel(dtm);

        for (int i = 1; i <= 31; i++) {
            denCB.addItem(i);
        }
        denCB.setSelectedItem(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
        for (int i = 1; i <= 12; i++) {
            mesiacCB.addItem(i);
        }
        mesiacCB.setSelectedItem(Calendar.getInstance().get(Calendar.MONTH));
        for (int i = 2012; i <= Calendar.getInstance().get(Calendar.YEAR) + 1; i++) {
            rokCB.addItem(i);
        }
        rokCB.setSelectedItem(Calendar.getInstance().get(Calendar.YEAR));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        removeButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        sviatkyTable = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        popisSviatku = new javax.swing.JTextField();
        newButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        denCB = new javax.swing.JComboBox();
        mesiacCB = new javax.swing.JComboBox();
        rokCB = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        importButton = new javax.swing.JButton();
        exportButton = new javax.swing.JButton();
        rokTabulkaCB = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sviatky");

        removeButton.setText("Odstrániť");
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });

        sviatkyTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Popis sviatku", "Dátum", "Odstránenie"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                true, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        sviatkyTable.setCellSelectionEnabled(true);
        jScrollPane2.setViewportView(sviatkyTable);

        jLabel2.setText("Dátum");

        newButton.setText("Pridať nový sviatok");
        newButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Popis");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(newButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(popisSviatku)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(denCB, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mesiacCB, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(rokCB, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(popisSviatku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(denCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mesiacCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rokCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(newButton)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 205, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 51, Short.MAX_VALUE)
        );

        importButton.setText("Import");
        importButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importButtonActionPerformed(evt);
            }
        });

        exportButton.setText("Export");
        exportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Rok:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 535, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(rokTabulkaCB, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(removeButton)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGap(69, 69, 69)
                            .addComponent(importButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(exportButton))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGap(61, 61, 61)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(40, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(71, 71, 71)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(removeButton)
                    .addComponent(importButton)
                    .addComponent(exportButton)
                    .addComponent(rokTabulkaCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
        // odstranenie vyznacenych sviatkov z tabulky
        ArrayList<Integer> indexyVymazat = new ArrayList<>();
        for (int i = 0; i < dtm.getRowCount(); i++) {
            if (dtm.getValueAt(i, 2) == true) {
                indexyVymazat.add(i);
            }
        }
        if (!indexyVymazat.isEmpty()) {
            try {
                removeSviatky(indexyVymazat);
            } catch (SQLException ex) {
                Logger.getLogger(SpravaSviatkov.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, "Nepodarilo sa odstrániť sviatky z databázy!", "Chyba", JOptionPane.ERROR_MESSAGE);
            }
            refreshTable();
        }
    }//GEN-LAST:event_removeButtonActionPerformed

    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        //vlozenie noveho sviatku
        try {
            try {
                String datum = "";
                if ((Integer) denCB.getSelectedItem() < 10) {
                    datum += '0';
                }
                datum += Integer.toString((Integer) denCB.getSelectedItem()) + ".";
                if ((Integer) mesiacCB.getSelectedItem() < 10) {
                    datum += '0';
                }
                datum += Integer.toString((Integer) mesiacCB.getSelectedItem()) + "." + Integer.toString((Integer) rokCB.getSelectedItem());
                if(popisSviatku.getText().equals("")){
                    JOptionPane.showMessageDialog(this, "Nesprávne zadaný názov sviatku!", "Chyba", JOptionPane.ERROR_MESSAGE);
                }else{
                    sviatky.addSviatok(new Sviatok(datum, popisSviatku.getText()));
                }
            } catch (SQLException ex) {
                Logger.getLogger(SpravaSviatkov.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, "Nepodarilo sa vložiť sviatok do databázy!", "Chyba", JOptionPane.ERROR_MESSAGE);
            }
        } catch (ParseException ex) {
            Logger.getLogger(SpravaSviatkov.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Nepodarilo sa vložiť sviatok do databázy!", "Chyba", JOptionPane.ERROR_MESSAGE);
        }
        try {
            sviatky = new Sviatky();
        } catch (SQLException | ParseException ex) {
            Logger.getLogger(SpravaSviatkov.class.getName()).log(Level.SEVERE, null, ex);
        }
        refreshTable();
    }//GEN-LAST:event_newButtonActionPerformed

    private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
        //importovanie sviatkov zo zvoleneho suboru
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
        chooser.setSelectedFile(new File("subor_so_sviatkami.csv"));
        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith(".csv") || f.isDirectory();
            }

            @Override
            public String getDescription() {
                return "CSV Files";
            }
        });
        int r = chooser.showOpenDialog(this);
        if (r == JFileChooser.APPROVE_OPTION) {
            String csvname = chooser.getSelectedFile().getPath();
            importSviatky(csvname);
        }
        refreshTable();
    }//GEN-LAST:event_importButtonActionPerformed

    private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
        //exportovanie sviatkov do vybraneho suboru
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
        chooser.setSelectedFile(new File("sviatky.csv"));
        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith(".csv") || f.isDirectory();
            }

            @Override
            public String getDescription() {
                return "CSV Files";
            }
        });
        int r = chooser.showSaveDialog(this);
        if (r == JFileChooser.APPROVE_OPTION) {
            String csvname = chooser.getSelectedFile().getPath();
            if (!csvname.endsWith(".csv")) {
                csvname += ".csv";
            }
            // ak existuje uz taky file, upozorni uzivatela
            boolean exists = (new File(csvname)).exists();
            if (exists) {
                int volba = JOptionPane.showConfirmDialog(this, "Rovnaký súbor už existuje, prajete si ho prepísať?", "Info", JOptionPane.YES_NO_OPTION);
                if (volba == JOptionPane.NO_OPTION) {
                    return;
                }
            }
            exportSviatky(csvname);
        }
    }//GEN-LAST:event_exportButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SpravaSviatkov.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SpravaSviatkov.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SpravaSviatkov.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SpravaSviatkov.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new SpravaSviatkov().setVisible(true);
            }
        });
    }

    private void refreshTable() {
        /**
         * Obnovenie tabuľky sviatkov podľa aktuálne zvoleného roka.
         */
        int rok = 0;
        if (rokTabulkaCB.getSelectedIndex() != 0) {
            rok = (Integer) rokTabulkaCB.getSelectedItem();
        }
        if (getSviatky(rok)) {
            dtm.setRowCount(0);

            for (int i = 0; i < sviatkyZoznam.size(); i++) {
                dtm.addRow(new Object[]{sviatkyZoznam.get(i).getPopis(), sviatkyZoznam.get(i).getDatum(), false});
            }
        }
    }

    private boolean getSviatky(int rok) {
        /**
         * Získa z databázy všetky sviatky ktoré sa nachádzajú v danom roku a
         * uloží ich do premennej sviatkyZoznam
         *
         * @param rok rok, v ktorom chceme získať sviatky
         */
        if (sviatky.isConnected()) {
            if (rok != 0) {
                sviatkyZoznam = sviatky.getSviatky(rok);
            } else {
                sviatkyZoznam = sviatky.getSviatky();
            }
            return true;
        } else {
            JOptionPane.showMessageDialog(this, "Nepodarilo sa načítať sviatky z databázy!", "Chyba", JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }
    
    /**
     * Nacita vsetky sviatky z databazy.
     *
     */
    private ArrayList<Sviatok> getVsetkySviatky() {
        if (sviatky.isConnected()) {
            return sviatky.getSviatky();
        }
        return null;
    }

    private void addSviatky(ArrayList<Sviatok> sv) throws SQLException {
        /**
         * Vloží zoznam sviatkov postupne do databázy.
         *
         * @param sv zoznam sviatkov
         */
        for (int i = 0; i < sv.size(); i++) {
            sviatky.addSviatok(sv.get(i));
        }
    }

    private void removeSviatky(ArrayList<Integer> sviatkyIndex) throws SQLException {
        /**
         * Odstráni zoznam sviatkov postupne z databázy.
         *
         * @param sviatkyIndex zoznam sviatkov
         */
        for (int i = sviatkyIndex.size()-1; i >= 0; i--) {
            sviatky.removeSviatok(sviatkyIndex.get(i));
        }
    }

    /**
     * Importuje zoznam sviatkov zo súboru pomocou ImportExportCSV.
     *
     * @param subor názov súboru
     */
    private void importSviatky(String subor) {
        try {

            if (!ie.importSviatky(subor)) {
                JOptionPane.showMessageDialog(this, "Nepodarilo sa importovať sviatky !", "Chyba", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Sviatky sa úspešne načítali.", "Info", JOptionPane.INFORMATION_MESSAGE);
                sviatky = new Sviatky();
                getSviatky(0);
                rokTabulkaCB.setSelectedIndex(0);
            }
        } catch (ParseException | SQLException ex) {
            Logger.getLogger(SpravaSviatkov.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Nepodarilo sa importovať sviatky !", "Chyba", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void exportSviatky(String subor) {
        ArrayList<Sviatok> vsetkySviatky = getVsetkySviatky();
        if(vsetkySviatky != null) {
            if (!ie.exportSviatky(subor, getVsetkySviatky())) {
                JOptionPane.showMessageDialog(this, "Nepodarilo sa exportovať sviatky !", "Chyba", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Sviatky boli uložené.", "Info", JOptionPane.INFORMATION_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(this, "Nepodarilo sa exportovať sviatky !", "Chyba", JOptionPane.ERROR_MESSAGE);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox denCB;
    private javax.swing.JButton exportButton;
    private javax.swing.JButton importButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox mesiacCB;
    private javax.swing.JButton newButton;
    private javax.swing.JTextField popisSviatku;
    private javax.swing.JButton removeButton;
    private javax.swing.JComboBox rokCB;
    private javax.swing.JComboBox rokTabulkaCB;
    private javax.swing.JTable sviatkyTable;
    // End of variables declaration//GEN-END:variables
}
